//
//  UIDcimView.m
//  UI07_DCIMHomework
//
//  Created by dllo on 16/6/14.
//  Copyright © 2016年 司昌宝. All rights reserved.
//

#import "UIDcimView.h"
#import "SecondViewController.h"

@interface UIDcimView ()

@property (nonatomic,retain)NSMutableArray<NSString *> *nameArray;

@end

@implementation UIDcimView

-(instancetype)initWithFrame:(CGRect)frame withNameArray:(NSMutableArray *)nameArray{
    self = [super initWithFrame:frame];
    if (self) {
        [self createImageViewWithNameArray:(NSMutableArray *)nameArray];
    }
    return self;
}

-(void)createImageViewWithNameArray:(NSMutableArray *)nameArray{
  //  UIView *backGroundView = [[UIView alloc] initWithFrame:self.frame];
    NSInteger tagNumber = 10000;
    for (NSInteger i = 0; i < 3; i++) {
        for(NSInteger j = 0;j < 2; j++) {
            
            UIImage *image = [UIImage imageNamed:[nameArray objectAtIndex:i * 2 + j]];
            
            UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
            imageView.frame = CGRectMake(j * self.frame.size.width * 0.5 + 10, i * self.frame.size.height * 0.3 + 64, self.frame.size.width * 0.5 - 20, self.frame.size.height * 0.3 - 10);
            [self addSubview:imageView];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
            [imageView addGestureRecognizer:tap];
            imageView.userInteractionEnabled = YES;
            imageView.tag = tagNumber;
            tagNumber++;
            [imageView release];
        }
    }
}

-(void)tapAction:(UITapGestureRecognizer *)tap{
    NSInteger index = [tap view].tag - 10000;
    [self.delegate nextViewControllerWith:index];
}
@end
